<template>
  <ul class="data-v-news" :style="hostStyle">
    <li
      v-for="(item, index) in list"
      :key="item.id"
      class="news-item"
      :class="[{ 'is-round': round }, { 'show-background': showBackground }]"
    >
      <div
        class="num"
        :class="[{ 'is-round': round }, { 'show-background': showBackground }]"
      >
        {{ index + 1 }}
      </div>
      <div class="text">{{ item.text }}</div>
    </li>
  </ul>
</template>

<script>
import { modifyOpacity } from '../color';

export default {
  name: "data-v-news",
  props: {
    list: {
      type: Array,
      default: function() {
        return [];
      }
    },
    round: {
      type: Boolean,
      default: false
    },
    showBackground: {
      type: Boolean,
      default: true
    },
    color: {
      type: String,
      default: '#0a8470'
    }
  },
  computed: {
    hostStyle(){
      return {
        '--color': this.color,
        '--color-even': modifyOpacity(this.color, 0.6),
        '--color-background': modifyOpacity(this.color, 0.3),
      }
    }
  }
};
</script>

<style lang="less">
.data-v-news {
  padding: 6px;
  margin: 5px;
  position: relative;
  ul {
    list-style: none;
    padding: 0;
    margin: 0;
  }
  .news-item {
    display: flex;
    border-bottom-right-radius: 10px;
    &.is-round {
      border: 1px solid var(--color);
      border-radius: 34px;
    }
    &.show-background {
      background: var(--color-background);
      &:nth-child(even) {
        background: var(--color-even);
      }
    }

    & + .news-item {
      margin-top: 10px;
    }

    .num {
      width: 34px;
      height: 34px;
      line-height: 34px;
      background: var(--color);
      text-align: center;
      &.is-round {
        border-radius: 50%;
      }
    }

    .text {
      padding-left: 10px;
      flex: 1;
      font-size: 14px;
      line-height: 34px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
</style>
